/*
 * Decompiled with CFR 0.151.
 * 
 * Could not load the following classes:
 *  nc.bs.framework.common.NCLocator
 *  nc.bs.gl.cashflowcase.CashFlowCaseBO
 *  nc.bs.gl.cashflowcase.CashFlowCaseOpDMO
 *  nc.bs.gl.cashflowcase.CashflowDMO
 *  nc.bs.gl.cashflowcase.CashflowcaseDMO
 *  nc.bs.gl.cashflowcaseio.CashFlowCaseIOBO
 *  nc.bs.gl.cashflowcaseio.CashFlowVOLoader
 *  nc.bs.gl.pubinterface.IVoucherDelete
 *  nc.bs.gl.pubinterface.IVoucherSave
 *  nc.bs.glcom.ass.assitem.cache.AccAssItemCache
 *  nc.bs.logging.Logger
 *  nc.bs.ml.NCLangResOnserver
 *  nc.bs.pub.DataManageObject
 *  nc.bs.pub.SystemException
 *  nc.bs.sec.esapi.NCESAPI
 *  nc.itf.fi.pub.Currency
 *  nc.itf.fipub.freevalue.IFreevalueReportQry
 *  nc.itf.fipub.freevalueset.IFreeMap
 *  nc.itf.gl.pub.ICfSaveCheckConst
 *  nc.itf.glcom.para.GLParaAccessor
 *  nc.md.gl.metadata.GlAccAssinfoVO
 *  nc.pubitf.bd.accessor.GeneralAccessorFactory
 *  nc.pubitf.bd.accessor.IGeneralAccessor
 *  nc.vo.bd.accessor.IBDData
 *  nc.vo.bd.accessor.bankaccsub.BankaccsubBDDataVO
 *  nc.vo.bd.account.AccountVO
 *  nc.vo.bd.currinfo.CurrinfoVO
 *  nc.vo.bd.currinfo.ICurrinfoConst
 *  nc.vo.fi.pub.SqlUtils
 *  nc.vo.fipub.freevalue.Module
 *  nc.vo.fipub.freevalue.util.FreeValueDefUtil
 *  nc.vo.gateway60.accountbook.AccountBookUtil
 *  nc.vo.gateway60.itfs.AccountByPkThreadCache
 *  nc.vo.gateway60.itfs.AccountUtilGL
 *  nc.vo.gateway60.itfs.Currency
 *  nc.vo.gateway60.itfs.GeneralThreadCache
 *  nc.vo.gateway60.itfs.IGeneralDataLoader
 *  nc.vo.gl.cashflowcase.CFPubProxy
 *  nc.vo.gl.cashflowcase.CashFlowForIUFOCondVO
 *  nc.vo.gl.cashflowcase.CashflowVO
 *  nc.vo.gl.cashflowcase.CashflowcaseVO
 *  nc.vo.gl.cashflowcase.CfVOAdapter
 *  nc.vo.gl.cashflowcase.QueryConditionVO
 *  nc.vo.gl.cashflowcase.SubrelationVO
 *  nc.vo.gl.cashflowcase.UFOCashFlowVO
 *  nc.vo.gl.cashflowcase.VoucherCFVO
 *  nc.vo.gl.cashflowcase.analyze.CashFlowSortTool
 *  nc.vo.gl.cashflowcase.analyze.CashflowAnalyzeExecutor
 *  nc.vo.gl.cashflowcase.analyze.CfAnalyzeEnvVO
 *  nc.vo.gl.commonvoucher.CommondetailVO
 *  nc.vo.gl.commonvoucher.CommonvoucherVO
 *  nc.vo.gl.pubinterface.VoucherOperateInterfaceVO
 *  nc.vo.gl.pubinterface.VoucherSaveInterfaceVO
 *  nc.vo.gl.pubvoucher.DetailVO
 *  nc.vo.gl.pubvoucher.OperationResultVO
 *  nc.vo.gl.pubvoucher.UserDataVO
 *  nc.vo.gl.pubvoucher.VoucherVO
 *  nc.vo.glcom.ass.AssCodeConstructor
 *  nc.vo.glcom.ass.AssVO
 *  nc.vo.glcom.tools.GLPubProxy
 *  nc.vo.jcom.lang.StringUtil
 *  nc.vo.ml.NCLangRes4VoTransl
 *  nc.vo.pub.BusinessException
 *  nc.vo.pub.lang.UFDate
 *  nc.vo.pub.lang.UFDouble
 */
package nc.bs.gl.cashflowcaseio;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.Vector;

import javax.naming.NamingException;

import nc.bs.framework.common.NCLocator;
import nc.bs.gl.cashflowcase.CashFlowCaseBO;
import nc.bs.gl.cashflowcase.CashFlowCaseOpDMO;
import nc.bs.gl.cashflowcase.CashflowDMO;
import nc.bs.gl.cashflowcase.CashflowcaseDMO;
import nc.bs.gl.pubinterface.IVoucherDelete;
import nc.bs.gl.pubinterface.IVoucherSave;
import nc.bs.glcom.ass.assitem.cache.AccAssItemCache;
import nc.bs.logging.Logger;
import nc.bs.ml.NCLangResOnserver;
import nc.bs.pub.DataManageObject;
import nc.bs.pub.SystemException;
import nc.bs.sec.esapi.NCESAPI;
import nc.itf.fi.pub.Currency;
import nc.itf.fipub.freevalue.IFreevalueReportQry;
import nc.itf.fipub.freevalueset.IFreeMap;
import nc.itf.gl.pub.ICfSaveCheckConst;
import nc.itf.glcom.para.GLParaAccessor;
import nc.md.gl.metadata.GlAccAssinfoVO;
import nc.pubitf.bd.accessor.GeneralAccessorFactory;
import nc.pubitf.bd.accessor.IGeneralAccessor;
import nc.vo.bd.accessor.IBDData;
import nc.vo.bd.accessor.bankaccsub.BankaccsubBDDataVO;
import nc.vo.bd.account.AccountVO;
import nc.vo.bd.currinfo.CurrinfoVO;
import nc.vo.bd.currinfo.ICurrinfoConst;
import nc.vo.fi.pub.SqlUtils;
import nc.vo.fipub.freevalue.Module;
import nc.vo.fipub.freevalue.util.FreeValueDefUtil;
import nc.vo.gateway60.accountbook.AccountBookUtil;
import nc.vo.gateway60.itfs.AccountByPkThreadCache;
import nc.vo.gateway60.itfs.AccountUtilGL;
import nc.vo.gateway60.itfs.GeneralThreadCache;
import nc.vo.gateway60.itfs.IGeneralDataLoader;
import nc.vo.gl.cashflowcase.CFPubProxy;
import nc.vo.gl.cashflowcase.CashFlowForIUFOCondVO;
import nc.vo.gl.cashflowcase.CashflowVO;
import nc.vo.gl.cashflowcase.CashflowcaseVO;
import nc.vo.gl.cashflowcase.CfVOAdapter;
import nc.vo.gl.cashflowcase.QueryConditionVO;
import nc.vo.gl.cashflowcase.SubrelationVO;
import nc.vo.gl.cashflowcase.UFOCashFlowVO;
import nc.vo.gl.cashflowcase.VoucherCFVO;
import nc.vo.gl.cashflowcase.analyze.CashFlowSortTool;
import nc.vo.gl.cashflowcase.analyze.CashflowAnalyzeExecutor;
import nc.vo.gl.cashflowcase.analyze.CfAnalyzeEnvVO;
import nc.vo.gl.commonvoucher.CommondetailVO;
import nc.vo.gl.commonvoucher.CommonvoucherVO;
import nc.vo.gl.pubinterface.VoucherOperateInterfaceVO;
import nc.vo.gl.pubinterface.VoucherSaveInterfaceVO;
import nc.vo.gl.pubvoucher.DetailVO;
import nc.vo.gl.pubvoucher.OperationResultVO;
import nc.vo.gl.pubvoucher.UserDataVO;
import nc.vo.gl.pubvoucher.VoucherVO;
import nc.vo.glcom.ass.AssCodeConstructor;
import nc.vo.glcom.ass.AssVO;
import nc.vo.glcom.tools.GLPubProxy;
import nc.vo.jcom.lang.StringUtil;
import nc.vo.ml.NCLangRes4VoTransl;
import nc.vo.pub.BusinessException;
import nc.vo.pub.lang.UFDate;
import nc.vo.pub.lang.UFDouble;

public class CashFlowCaseIODMO
extends DataManageObject
implements IVoucherSave,
IVoucherDelete,
ICfSaveCheckConst {
    public CashFlowCaseIODMO() throws NamingException, SystemException {
    }

    public CashFlowCaseIODMO(String dbName) throws NamingException, SystemException {
        super(dbName);
    }

    public OperationResultVO[] afterSave(VoucherSaveInterfaceVO vo) throws BusinessException {
        OperationResultVO v;
        String pa = null;
        Logger.debug((Object)vo.voucher);
        OperationResultVO[] vs = new OperationResultVO[1];
        OperationResultVO rs = new OperationResultVO();
        if (vo.voucher.getVoucherkind() == 2) {
            vs[0] = rs;
            return vs;
        }
        vs[0] = v = this.afterSaveForJitAnalyze(vo.voucher);
        if (vs != null && vs.length > 0 && vs[0].m_intSuccess == 2) {
            return vs;
        }
        try {
            pa = GLPubProxy.getRemoteGlPara().isCheckCFSaveVoucher(vo.voucher.getPk_accountingbook());
        }
        catch (Exception e) {
            this.reportException(e);
            throw new BusinessException(NCLangResOnserver.getInstance().getStrByID("200235", "UPP200235-000012"));
        }
        OperationResultVO[] or = this.analyseError(pa, vo);
        return or;
    }

    private boolean autoAnalyzeCashflow(VoucherVO voucher) throws BusinessException {
        String pa = GLPubProxy.getRemoteGlPara().isCheckCFSaveVoucher(voucher.getPk_accountingbook());
        if (pa != null && pa.trim().equals("3")) {
            return false;
        }
        boolean isHasCashFlowModified = false;
        DetailVO[] detailVOs = voucher.getDetails();
        if (detailVOs != null && detailVOs.length > 0) {
            for (int i = 0; i < detailVOs.length; ++i) {
                if (detailVOs[i] == null || detailVOs[i].getCashFlow() == null || detailVOs[i].getCashFlow().length <= 0) continue;
                isHasCashFlowModified = true;
                break;
            }
        }
        if (isHasCashFlowModified) {
            return false;
        }
        DetailVO[] vos = voucher.getDetails();
        vos = this.initFidetail(voucher);
        HashMap<String, DetailVO> map = null;
        for (int i = 0; i < vos.length; ++i) {
            if (map == null) {
                map = new HashMap<String, DetailVO>();
            }
            map.put(vos[i].getPk_detail(), vos[i]);
        }
        VoucherCFVO[] cfvos = CfVOAdapter.transferToVoucherVO((DetailVO[])vos);
        CfAnalyzeEnvVO env = new CfAnalyzeEnvVO();
        env.setAnalyzeType("");
        env.setM_pk_glorgbook(voucher.getPk_accountingbook());
        CashflowVO qryVO = new CashflowVO();
        qryVO.setPk_glorgbook(voucher.getPk_accountingbook());
        CashFlowCaseBO cfbo = new CashFlowCaseBO();
        CashflowVO[] cashflows = this.queryCashFlowByPk_accountingbook(voucher.getPk_accountingbook());
        env.setCashflows(cashflows);
        SubrelationVO[] subRelation = CFPubProxy.getRemoteCashFlowCase().querySubByBookAndDate(voucher.getPk_accountingbook(), voucher.getPrepareddate().toStdString(), false);
        new CashFlowSortTool().SortVos(subRelation);
        env.fillSubRelation(subRelation);
        env.setSubflag(true);
        Vector<CashflowcaseVO> cfcases = new Vector();
        if (GLParaAccessor.isLiabilitycenterBalCheck((String)voucher.getPk_org())) {
            HashSet<String> liabilitycenterSet = new HashSet<String>();
            for (VoucherCFVO detail : cfvos) {
                if (StringUtil.isEmptyWithTrim((String)detail.getPk_liabilitycenter())) continue;
                liabilitycenterSet.add(detail.getPk_liabilitycenter());
            }
            if (liabilitycenterSet.size() > 1) {
                HashMap<String, List<VoucherCFVO>> cfvoMap = new HashMap();
                ArrayList<String> liabilitycenterList = new ArrayList<String>();
                for (VoucherCFVO cfvo : cfvos) {
                    if (StringUtil.isEmptyWithTrim((String)cfvo.getPk_liabilitycenter())) continue;
                    if (cfvoMap.get(cfvo.getPk_liabilitycenter()) == null) {
                        cfvoMap.put(cfvo.getPk_liabilitycenter(), new ArrayList());
                        liabilitycenterList.add(cfvo.getPk_liabilitycenter());
                    }
                    ((List)cfvoMap.get(cfvo.getPk_liabilitycenter())).add(cfvo);
                }
                for (String key : liabilitycenterList) {
                    env.setVos(((List<VoucherCFVO>)cfvoMap.get(key)).toArray(new VoucherCFVO[0]));
                    Vector cashflowcasevo = new CashflowAnalyzeExecutor().execute(env);
                    if (cashflowcasevo == null) continue;
                    cfcases.addAll(cashflowcasevo);
                }
            } else {
                env.setVos(cfvos);
                Vector cashflowcasevo = new CashflowAnalyzeExecutor().execute(env);
                if (cashflowcasevo != null) {
                    cfcases.addAll(cashflowcasevo);
                }
            }
        } else {
            env.setVos(cfvos);
            Vector cashflowcasevo = new CashflowAnalyzeExecutor().execute(env);
            if (cashflowcasevo != null) {
                cfcases.addAll(cashflowcasevo);
            }
        }
        if (cfcases != null && cfcases.size() > 0) {
            HashMap<String, ArrayList<CashflowcaseVO>> cfmap = new HashMap<String, ArrayList<CashflowcaseVO>>();
            for (CashflowcaseVO cfcase : cfcases) {
                ArrayList<CashflowcaseVO> list = (ArrayList<CashflowcaseVO>)cfmap.get(cfcase.getPk_detail());
                if (list == null) {
                    list = new ArrayList<CashflowcaseVO>();
                    cfmap.put(cfcase.getPk_detail(), list);
                }
                list.add(cfcase);
            }
            for (DetailVO detail : vos) {
                ArrayList list = (ArrayList)cfmap.get(detail.getPk_detail());
                if (list == null) continue;
                detail.setCashFlow((CashflowcaseVO[]) list.toArray(new CashflowcaseVO[0]));
            }
            return true;
        }
        return false;
    }

    public OperationResultVO afterSaveForJitAnalyze(VoucherVO voucher) throws BusinessException {
        OperationResultVO rs = new OperationResultVO();
        rs.m_intSuccess = 0;
        if (voucher == null) {
            return rs;
        }
        rs.m_strPK = voucher.getPk_voucher();
        DetailVO[] vos = voucher.getDetails();
        if (vos == null || vos.length < 1) {
            return rs;
        }
        this.autoAnalyzeCashflow(voucher);
        try {
            CashflowcaseDMO dmo = new CashflowcaseDMO();
            CashFlowCaseOpDMO ddo = new CashFlowCaseOpDMO();
            ddo.deleteByDetails(voucher, vos);
            HashSet<CashflowcaseVO> cashflowcaseVOSet = new HashSet<CashflowcaseVO>();
            for (int i = 0; i < vos.length; ++i) {
                CashflowcaseVO[] cashflows = vos[i].getCashFlow();
                if (cashflows == null || cashflows.length <= 0) continue;
                for (int j = 0; j < cashflows.length; ++j) {
                    cashflows[j].setPk_detail(vos[i].getPk_detail());
                    cashflows[j].setPk_detail_opp(cashflows[j].getM_pk_currtype());
                    cashflows[j].setPk_glorgbook(vos[i].getPk_accountingbook());
                    if (cashflows[j].getPk_unit() != null) continue;
                    cashflows[j].setPk_unit(vos[i].getPk_unit());
                }
                cashflowcaseVOSet.addAll(Arrays.asList(cashflows));
            }
            if (cashflowcaseVOSet.size() > 0) {
                dmo.insertArray(cashflowcaseVOSet.toArray(new CashflowcaseVO[0]), false);
            }
        }
        catch (Exception e) {
            this.reportException(e);
            rs.m_intSuccess = 2;
            rs.m_strDescription = NCLangResOnserver.getInstance().getStrByID("200235", "UPP200235-000014");
        }
        return rs;
    }

    public void saveCommonVoucherCF(CommonvoucherVO voucher) throws BusinessException {
        Vector vos = voucher.getCommonDetails();
        Vector cashflowV = new Vector();
        try {
            int i;
            CashflowcaseDMO dmo = new CashflowcaseDMO();
            CashFlowCaseOpDMO ddo = new CashFlowCaseOpDMO();
            CashflowcaseVO deleteVO = new CashflowcaseVO();
            for (i = 0; i < vos.size(); ++i) {
                deleteVO.setPk_glorgbook(((CommondetailVO)vos.get(i)).getPk_glorgbook());
                deleteVO.setPk_sob(((CommondetailVO)vos.get(i)).getPk_commondetail());
                deleteVO.setPk_detail(((CommondetailVO)vos.get(i)).getPk_commondetail());
                ddo.deleteCashflowcase(deleteVO);
            }
            for (i = 0; i < vos.size(); ++i) {
                CashflowcaseVO[] cashflows = ((CommondetailVO)vos.get(i)).getCashFlow();
                if (cashflows == null || cashflows.length <= 0) continue;
                for (int j = 0; j < cashflows.length; ++j) {
                    cashflows[j].setPk_detail(((CommondetailVO)vos.get(i)).getPk_commondetail());
                    cashflows[j].setPk_detail_opp(((CommondetailVO)vos.get(i)).getPk_currtype());
                    cashflows[j].setPk_glorgbook(((CommondetailVO)vos.get(i)).getPk_glorgbook());
                }
                String[] stringArray = dmo.insertArray(cashflows, false);
            }
        }
        catch (Exception exception) {
            // empty catch block
        }
    }

    public OperationResultVO afterSave(VoucherVO voucher, Object objUserData) throws BusinessException {
        CashflowcaseVO dvo;
        OperationResultVO rs = new OperationResultVO();
        rs.m_intSuccess = 0;
        if (voucher == null) {
            return rs;
        }
        rs.m_strPK = voucher.getPk_voucher();
        DetailVO[] vos = voucher.getDetails();
        vos = this.initFidetail(voucher);
        if (vos == null || vos.length < 1) {
            return rs;
        }
        Vector<CashflowcaseVO> cashflowV = new Vector<CashflowcaseVO>();
        Vector<String> v_deleteDetailPK = new Vector<String>();
        block6: for (int i = 0; i < vos.length; ++i) {
            Vector v = vos[i].getOtheruserdata();
            if (v == null || v.size() <= 0) continue;
            for (int j = 0; j < v.size(); ++j) {
                UserDataVO udvo = (UserDataVO)v.elementAt(j);
                if (udvo == null || !udvo.getDatatype().endsWith("\u73b0\u91d1\u6d41\u91cf")) continue;
                try {
                    CashflowcaseVO[] temps = (CashflowcaseVO[])udvo.getUserdata();
                    if (temps == null) {
                        v_deleteDetailPK.addElement(vos[i].getPk_detail());
                        continue block6;
                    }
                    CashflowcaseVO[] tempsClone = new CashflowcaseVO[temps.length];
                    for (int m = 0; m < temps.length; ++m) {
                        tempsClone[m] = (CashflowcaseVO)temps[m].clone();
                    }
                    for (int k = 0; k < tempsClone.length; ++k) {
                        if (vos[i].getPk_detail() == null) continue;
                        tempsClone[k].setPk_corp(vos[i].getPk_org());
                        tempsClone[k].setPk_glorgbook(vos[i].getPk_glorgbook());
                        tempsClone[k].setPk_detail(vos[i].getPk_detail());
                        cashflowV.add(tempsClone[k]);
                    }
                    continue;
                }
                catch (ClassCastException temps) {
                    // empty catch block
                }
            }
        }
        CashflowcaseVO[] cashflows = new CashflowcaseVO[cashflowV.size()];
        cashflowV.copyInto(cashflows);
        if (cashflows.length > 0) {
            try {
                CashflowcaseDMO dmo = new CashflowcaseDMO();
                CashFlowCaseOpDMO ddo = new CashFlowCaseOpDMO();
                dvo = new CashflowcaseVO();
                for (int i = 0; i < cashflows.length; ++i) {
                    dvo.setPk_glorgbook(cashflows[i].getPk_glorgbook());
                    dvo.setPk_detail(cashflows[i].getPk_detail());
                    ddo.deleteCashflowcase(dvo);
                }
                String[] i = dmo.insertArray((CashflowcaseVO[])cashflows, false);
            }
            catch (Exception e) {
                this.reportException(e);
                rs.m_intSuccess = 2;
                rs.m_strDescription = NCLangResOnserver.getInstance().getStrByID("200235", "UPP200235-000014");
            }
        }
        if (v_deleteDetailPK.size() > 0) {
            Object[] deleteDetailPKs = new String[v_deleteDetailPK.size()];
            v_deleteDetailPK.copyInto(deleteDetailPKs);
            try {
                CashFlowCaseOpDMO ddo = new CashFlowCaseOpDMO();
                dvo = new CashflowcaseVO();
                for (int i = 0; i < deleteDetailPKs.length; ++i) {
                    dvo.setPk_detail((String)deleteDetailPKs[i]);
                    ddo.deleteCashflowcase(dvo);
                }
            }
            catch (Exception e) {
                this.reportException(e);
                rs.m_intSuccess = 2;
                rs.m_strDescription = NCLangResOnserver.getInstance().getStrByID("200235", "UPP200235-000014");
            }
        }
        return rs;
    }

    public OperationResultVO[] analyseError(String pa, VoucherSaveInterfaceVO vo) {
        OperationResultVO[] orSub;
        OperationResultVO rs = new OperationResultVO();
        OperationResultVO[] vs = new OperationResultVO[]{rs};
        VoucherVO voucher = vo.voucher;
        if (voucher == null || voucher.getDetails() == null) {
            return vs;
        }
        if (voucher.getVoucherkind() == 2) {
            return vs;
        }
        if (pa.trim().equals("3")) {
            return vs;
        }
        DetailVO[] vos = voucher.getDetails();
        HashMap<Object, Object> accMap = new HashMap<Object, Object>();
        if (pa.trim().equals("1") || pa.trim().equals("2")) {
            try {
                String[] pk_acc = new String[vos.length];
                for (int i = 0; i < vos.length; ++i) {
                    pk_acc[i] = vos[i].getPk_accasoa();
                }
                AccountVO[] accVOs = null;
                accVOs = voucher.getPrepareddate() != null ? AccountUtilGL.queryByPks((String[])pk_acc, (String)voucher.getPrepareddate().toStdString()) : AccountUtilGL.queryByPks((String[])pk_acc);
                if (accVOs == null) {
                    return vs;
                }
                for (int i = 0; i < accVOs.length; ++i) {
                    if (accVOs[i].getCashtype() == null || accVOs[i].getCashtype() > 0) {
                        // empty if block
                    }
                    accMap.put(accVOs[i].getPk_accasoa(), accVOs[i]);
                }
                int checkResult = this.isErrorInWhole(vos, accMap, voucher.getPk_accountingbook());
                if (checkResult != 0) {
                    rs.m_intSuccess = 2;
                    if (checkResult == 1) {
                        rs.m_strDescription = NCLangRes4VoTransl.getNCLangRes().getStrByID("2002gl55", "UPP2002gl55-000740");
                    }
                    if (checkResult == 2) {
                        rs.m_strDescription = NCLangRes4VoTransl.getNCLangRes().getStrByID("2002gl55", "UPP2002gl55-000741");
                    }
                    return vs;
                }
            }
            catch (Exception e) {
                this.reportException(e);
                rs.m_intSuccess = 2;
                rs.m_strDescription = NCLangRes4VoTransl.getNCLangRes().getStrByID("2002gl55", "UPP2002gl55-000742");
            }
        }
        if (pa.trim().equals("2") && (orSub = this.checkSubAssSetting(vo, accMap)) != null && orSub.length > 0) {
            return orSub;
        }
        return vs;
    }

    private DetailVO[] initFidetail(VoucherVO voucher) {
        int i;
        DetailVO[] vos = voucher.getDetails();
        Vector<DetailVO> fivector = new Vector<DetailVO>();
        HashSet<String> accset = new HashSet<String>();
        String[] pk_acc = new String[vos.length];
        for (int i2 = 0; i2 < vos.length; ++i2) {
            pk_acc[i2] = vos[i2].getPk_accasoa();
        }
        AccountVO[] accVOs = null;
        try {
            accVOs = voucher.getPrepareddate() != null ? AccountUtilGL.queryByPks((String[])pk_acc, (String)voucher.getPrepareddate().toStdString()) : AccountUtilGL.queryByPks((String[])pk_acc);
        }
        catch (Exception e) {
            this.reportException(e);
        }
        if (accVOs != null && accVOs.length > 0) {
            for (int i3 = 0; i3 < accVOs.length; ++i3) {
                if (accVOs[i3].getAccproperty() != null && accVOs[i3].getAccproperty() != 0) continue;
                accset.add(accVOs[i3].getPk_accasoa());
            }
        }
        for (i = 0; i < vos.length; ++i) {
            if (!accset.contains(vos[i].getPk_accasoa())) continue;
            fivector.add(vos[i]);
        }
        DetailVO[] fivos = new DetailVO[fivector.size()];
        for (i = 0; i < fivector.size(); ++i) {
            fivos[i] = (DetailVO)fivector.get(i);
        }
        return fivos;
    }

    public OperationResultVO[] analyseError1(VoucherSaveInterfaceVO vo) throws BusinessException {
        OperationResultVO rs;
        OperationResultVO[] vs = new OperationResultVO[1];
        VoucherVO voucher = vo.voucher;
        vs[0] = rs = new OperationResultVO();
        if (voucher.getVoucherkind() == 2) {
            return vs;
        }
        rs.m_intSuccess = 0;
        if (voucher == null) {
            return vs;
        }
        rs.m_strPK = voucher.getPk_voucher();
        DetailVO[] vos = voucher.getDetails();
        if (vos == null || vos.length < 1) {
            return vs;
        }
        Vector cashflowV = new Vector();
        UFDouble money1 = new UFDouble(0);
        UFDouble money2 = new UFDouble(0);
        String[] pk_acc = new String[vos.length];
        try {
            for (int i = 0; i < vos.length; ++i) {
                pk_acc[i] = vos[i].getPk_accasoa();
            }
            AccountVO[] accVOs = AccountUtilGL.queryByPks((String[])pk_acc);
            boolean flag = false;
            block3: for (int i = 0; i < vos.length; ++i) {
                Vector v;
                flag = false;
                for (int j = 0; j < accVOs.length; ++j) {
                    if (!accVOs[j].getPk_accasoa().equals(vos[i].getPk_accasoa())) continue;
                    if (accVOs[j].getCashtype() > 0) {
                        if (vos[i].getDebitamount().doubleValue() != 0.0) {
                            money2 = money2.add(vos[i].getDebitamount());
                            continue;
                        }
                        money2 = money2.sub(vos[i].getCreditamount());
                        continue;
                    }
                    flag = true;
                    break;
                }
                if (flag || (v = vos[i].getOtheruserdata()) == null || v.size() <= 0) continue;
                for (int j = 0; j < v.size(); ++j) {
                    UserDataVO udvo = (UserDataVO)v.elementAt(j);
                    if (udvo == null || !udvo.getDatatype().endsWith("\u73b0\u91d1\u6d41\u91cf")) continue;
                    CashflowcaseVO[] temps = (CashflowcaseVO[])udvo.getUserdata();
                    if (temps == null) continue block3;
                    for (int k = 0; k < temps.length; ++k) {
                        if (vos[i].getPk_detail() == null || temps[k].getCashflowFlag() != 0) continue;
                        money1 = temps[k].getFlag() == 1 ? money1.add(temps[k].getMoney()) : money1.sub(temps[k].getMoney());
                    }
                }
            }
            if (money1.doubleValue() - money2.doubleValue() != 0.0) {
                rs.m_intSuccess = 2;
                rs.m_strDescription = NCLangResOnserver.getInstance().getStrByID("200235", "UPP200235-000017");
            }
        }
        catch (Exception e) {
            this.reportException(e);
            rs.m_intSuccess = 2;
            rs.m_strDescription = NCLangResOnserver.getInstance().getStrByID("200235", "UPP200235-000018");
        }
        return vs;
    }

    public OperationResultVO beforeSave(Object objUserData) throws BusinessException {
        return null;
    }

    public OperationResultVO[] beforeSave(VoucherSaveInterfaceVO vo) throws BusinessException {
        return null;
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    public int getCashFlowC(String key, String pk_corp) throws SQLException {
        this.beforeCallMethod("nc.bs.gl.cashflowcase.CashflowDMO", "getCashFlowC", new Object[]{key});
        String sql = "";
        sql = "select count(pk_cashflow) from bd_cashflow where fathernode = '" + NCESAPI.sqlEncode((String)key) + "' and pk_corp = '" + NCESAPI.sqlEncode((String)pk_corp) + "'";
        int result = 0;
        Connection con = null;
        PreparedStatement stmt = null;
        try {
            con = this.getConnection();
            stmt = con.prepareStatement(sql);
            try (ResultSet rs = stmt.executeQuery();){
                while (rs.next()) {
                    result = rs.getInt(1);
                }
            }
        }
        finally {
            try {
                if (stmt != null) {
                    stmt.close();
                }
            }
            catch (Exception exception) {}
            try {
                if (con != null) {
                    con.close();
                }
            }
            catch (Exception exception) {}
        }
        this.afterCallMethod("nc.bs.gl.cashflowcase.CashflowDMO", "getCashFlowC", new Object[]{key});
        return result;
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    public String getCorp(String unitCode) throws SQLException {
        this.beforeCallMethod("nc.bs.gl.cashflowcaseio.CashFlowCaseIODMO", "getCorp", new Object[]{unitCode});
        if (unitCode == null) {
            return null;
        }
        String sqls = "select pk_corp from bd_corp where unitcode = '" + NCESAPI.sqlEncode((String)unitCode) + "'";
        String res = null;
        Connection con = null;
        PreparedStatement stmt = null;
        try {
            con = this.getConnection();
            stmt = con.prepareStatement(sqls);
            try (ResultSet rs = stmt.executeQuery();){
                while (rs.next()) {
                    Object t1 = rs.getObject(1);
                    if (t1 == null) continue;
                    res = t1.toString();
                }
            }
        }
        finally {
            try {
                if (stmt != null) {
                    stmt.close();
                }
            }
            catch (Exception exception) {}
            try {
                if (con != null) {
                    con.close();
                }
            }
            catch (Exception exception) {}
        }
        this.afterCallMethod("nc.bs.gl.cashflowcaseio.CashFlowCaseIODMO", "getCorp", new Object[]{unitCode});
        return res;
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    public UFDouble getXJLL(String pk_corp, String pk_glorgbook, UFDate date1, UFDate date2, String pk_cashflow, boolean flag) throws SQLException {
        this.beforeCallMethod("nc.bs.gl.cashflowcaseio.CashFlowCaseIODMO", "getXJLL", new Object[]{pk_cashflow});
        if (pk_cashflow == null) {
            return null;
        }
        String sqls = "select sum(cashflow.money) ";
        sqls = sqls + " from bd_cashflow left outer join  ";
        sqls = sqls + " (select pk_cashflow,money from gl_cashflowcase , ";
        sqls = sqls + " (select gl_detail.pk_detail from gl_voucher,gl_detail where ";
        sqls = sqls + "  gl_voucher.discardflag = 'N' ";
        sqls = sqls + " and gl_voucher.dr = 0 ";
        sqls = sqls + " and isnull(gl_voucher.errmessage,'~')='~' ";
        sqls = sqls + " and gl_voucher.voucherkind not in  (2,4,5,255) ";
        sqls = sqls + " and gl_voucher.pk_voucher = gl_detail.pk_voucher ";
        if (pk_glorgbook != null) {
            sqls = sqls + " and gl_voucher.pk_glorgbook = '" + NCESAPI.sqlEncode((String)pk_glorgbook) + "' ";
        }
        sqls = sqls + " and gl_voucher.prepareddate >= '" + date1 + "' and gl_voucher.prepareddate <= '" + date2 + "'";
        if (!flag) {
            sqls = sqls + " and gl_voucher.pk_manager <> 'N/A' ";
        }
        sqls = sqls + " ) voucher where gl_cashflowcase.pk_detail = voucher.pk_detail ";
        sqls = sqls + " ) cashflow on cashflow.pk_cashflow = bd_cashflow.pk_cashflow ";
        sqls = sqls + " where (bd_cashflow.pk_corp = '" + NCESAPI.sqlEncode((String)pk_corp) + "' or bd_cashflow.pk_corp = '0001')";
        sqls = sqls + " and bd_cashflow.pk_cashflow = '" + NCESAPI.sqlEncode((String)pk_cashflow) + "'";
        UFDouble res = new UFDouble(0);
        Connection con = null;
        PreparedStatement stmt = null;
        try {
            con = this.getConnection();
            stmt = con.prepareStatement(sqls);
            try (ResultSet rs = stmt.executeQuery();){
                while (rs.next()) {
                    Object t1 = rs.getObject(1);
                    if (t1 == null) continue;
                    res = new UFDouble(t1.toString());
                }
            }
        }
        finally {
            try {
                if (stmt != null) {
                    stmt.close();
                }
            }
            catch (Exception exception) {}
            try {
                if (con != null) {
                    con.close();
                }
            }
            catch (Exception exception) {}
        }
        this.afterCallMethod("nc.bs.gl.cashflowcaseio.CashFlowCaseIODMO", "getXJLL", new Object[]{pk_cashflow});
        return res;
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    public UFDouble getXJLLOfCurrtype(String pk_corp, String pk_glorgbook, UFDate date1, UFDate date2, String pk_cashflow, boolean flag, String pk_currtype, String rtnCurrtype) throws SQLException {
        this.beforeCallMethod("nc.bs.gl.cashflowcaseio.CashFlowCaseIODMO", "getXJLL", new Object[]{pk_cashflow});
        if (pk_cashflow == null) {
            return null;
        }
        String sqls = "";
        sqls = rtnCurrtype.equals("\u8d26\u7c3f\u672c\u5e01") ? sqls + "select sum(cashflow.moneymain) " : (rtnCurrtype.equals("\u96c6\u56e2\u672c\u5e01") ? sqls + "select sum(cashflow.moneygroup) " : (rtnCurrtype.equals("\u5168\u5c40\u672c\u5e01") ? sqls + "select sum(cashflow.moneyglobal) " : (rtnCurrtype.equals("\u539f\u5e01") ? sqls + "select sum(cashflow.money) " : sqls + " select sum(cashflow.moneymain) ")));
        sqls = sqls + " from bd_cashflow left outer join  ";
        sqls = sqls + " (select pk_cashflow,money,moneymain,moneyass from gl_cashflowcase , ";
        sqls = sqls + " (select gl_detail.pk_detail from gl_voucher,gl_detail where ";
        sqls = sqls + "  gl_voucher.discardflag = 'N' ";
        sqls = sqls + " and gl_voucher.dr = 0 ";
        sqls = sqls + " and isnull(gl_voucher.errmessage,'~')='~' ";
        sqls = sqls + " and gl_voucher.voucherkind not in  (2,4,5,255) ";
        sqls = sqls + " and gl_voucher.pk_voucher = gl_detail.pk_voucher ";
        if (pk_glorgbook != null) {
            sqls = sqls + " and gl_voucher.pk_glorgbook = '" + NCESAPI.sqlEncode((String)pk_glorgbook) + "' ";
        }
        sqls = sqls + " and gl_detail.pk_currtype = '" + NCESAPI.sqlEncode((String)pk_currtype) + "' ";
        sqls = sqls + " and gl_voucher.prepareddate >= '" + date1 + "' and gl_voucher.prepareddate <= '" + date2 + "'";
        if (!flag) {
            sqls = sqls + " and gl_voucher.pk_manager <> 'N/A' ";
        }
        sqls = sqls + " ) voucher where gl_cashflowcase.pk_detail = voucher.pk_detail ";
        sqls = sqls + " ) cashflow on cashflow.pk_cashflow = bd_cashflow.pk_cashflow ";
        sqls = sqls + " where (bd_cashflow.pk_corp = '" + NCESAPI.sqlEncode((String)pk_corp) + "' or bd_cashflow.pk_corp = '0001')";
        sqls = sqls + " and bd_cashflow.pk_cashflow = '" + NCESAPI.sqlEncode((String)pk_cashflow) + "'";
        UFDouble res = new UFDouble(0);
        Connection con = null;
        PreparedStatement stmt = null;
        try {
            con = this.getConnection();
            stmt = con.prepareStatement(sqls);
            try (ResultSet rs = stmt.executeQuery();){
                while (rs.next()) {
                    Object t1 = rs.getObject(1);
                    if (t1 == null) continue;
                    res = new UFDouble(t1.toString());
                }
            }
        }
        finally {
            try {
                if (stmt != null) {
                    stmt.close();
                }
            }
            catch (Exception exception) {}
            try {
                if (con != null) {
                    con.close();
                }
            }
            catch (Exception exception) {}
        }
        this.afterCallMethod("nc.bs.gl.cashflowcaseio.CashFlowCaseIODMO", "getXJLL", new Object[]{pk_cashflow});
        return res;
    }

    public UFDouble getXJLLOfCJurrtypeEx(CashFlowForIUFOCondVO qryVO) throws Exception {
        String pk_corps = qryVO.getOrgCode();
        String[] pk_glorgbooks = qryVO.getGlorgbooks();
        String subjCode = qryVO.getSubjCode();
        AssVO[] assItems = qryVO.getAssItems();
        UFDate date1 = qryVO.getStartdate();
        UFDate date2 = qryVO.getEnddate();
        String pk_cashflow = qryVO.getPk_cashflow();
        boolean flag = qryVO.getContainUnTally();
        String pk_currtype = qryVO.getPk_currtype();
        String rtnCurrtype = qryVO.getRtCuryType();
        String isDiff = qryVO.getIsDiff();
        boolean includeSub = qryVO.isIncludeSub();
        String pk_innercorp = qryVO.getPk_innercorp();
        String pk_unit = qryVO.getPk_unit();
        if (pk_cashflow == null) {
            return null;
        }
        StringBuilder pk_glorgbookssql = null;
        if (pk_glorgbooks != null && pk_glorgbooks.length > 0) {
            pk_glorgbookssql = new StringBuilder("");
            for (int i = 0; i < pk_glorgbooks.length; ++i) {
                pk_glorgbookssql.append("'").append(pk_glorgbooks[i]).append("'");
                if (i >= pk_glorgbooks.length - 1) continue;
                pk_glorgbookssql.append(",");
            }
        }
        if (pk_glorgbookssql == null) {
            return null;
        }
        UFDouble res = new UFDouble(0);
        Connection con = null;
        PreparedStatement stmt = null;
        try {
            AccountVO[] accounts = null;
            if (subjCode != null) {
                accounts = AccountUtilGL.getEndChildrenByCode((String[])pk_glorgbooks, (String)date2.toString(), (String)subjCode, (String)subjCode, (boolean)true, null);
            }
            String accwhere = "";
            if (accounts != null) {
                String[] pk_accasoas = new String[accounts.length];
                for (int i = 0; i < accounts.length; ++i) {
                    pk_accasoas[i] = accounts[i].getPk_accasoa();
                }
                accwhere = SqlUtils.getInStr((String)"gl_detail.pk_accasoa", (String[])pk_accasoas, (boolean)true);
            }
            StringBuffer sqls = new StringBuffer("");
            if (rtnCurrtype.equals("\u8d26\u7c3f\u672c\u5e01")) {
                sqls.append("select sum(cashflow.moneymain) ");
            } else if (rtnCurrtype.equals("\u96c6\u56e2\u672c\u5e01")) {
                sqls.append("select sum(cashflow.moneygroup) ");
            } else if (rtnCurrtype.equals("\u5168\u5c40\u672c\u5e01")) {
                sqls.append("select sum(cashflow.moneyglobal) ");
            } else if (rtnCurrtype.equals("\u539f\u5e01")) {
                sqls.append("select sum(cashflow.money) ");
            } else {
                sqls.append(" select sum(cashflow.moneymain) ");
            }
            String[] mergsqls = ((IFreevalueReportQry)NCLocator.getInstance().lookup(IFreevalueReportQry.class)).formSqlByAssvos(assItems, null, Module.GL);
            sqls.append(" from bd_cashflow left outer join  ");
            sqls.append(" (select pk_cashflow,money,moneymain from gl_cashflowcase , ");
            sqls.append(" (select pk_detail,pk_currtype from gl_detail");
            if (mergsqls != null) {
                sqls.append("," + mergsqls[0]);
            }
            sqls.append(" where gl_detail.discardflagv = 'N' ");
            sqls.append(" and gl_detail.TEMPSAVEFLAG = 'N'");
            sqls.append(" and gl_detail.dr = 0 ");
            sqls.append(" and isnull(gl_detail.errmessage,'~')='~' ");
            sqls.append(" and isnull(gl_detail.errmessage2,'~')='~' ");
            sqls.append(" and gl_detail.voucherkindv not in  (2,4,5,255) ");
            if (isDiff != null && !isDiff.equals("2")) {
                sqls.append(" and gl_detail.isdifflag = " + (isDiff.equals("0") ? "'N' " : "'Y' "));
            }
            if (pk_glorgbooks != null) {
                sqls.append(" and gl_detail.pk_accountingbook in (" + pk_glorgbookssql.toString() + ") ");
            }
            sqls.append(" and gl_detail.prepareddatev >= '" + date1.toString() + "' and gl_detail.prepareddatev <= '" + date2.toString() + "'");
            if (!flag) {
                sqls.append(" and gl_detail.pk_managerv <> 'N/A' ");
            }
            if (pk_unit != null && !pk_unit.trim().equals("")) {
                sqls.append(" and gl_detail.pk_unit = '" + pk_unit + "' ");
            }
            if (qryVO.getPk_profitcenter() != null && !qryVO.getPk_profitcenter().trim().equals("")) {
                sqls.append(" and gl_detail.pk_liabilitycenter = '" + qryVO.getPk_profitcenter() + "' ");
            }
            if (accounts != null && accounts.length > 0) {
                sqls.append(" and ").append(accwhere);
            }
            if (mergsqls != null) {
                sqls.append(" and gl_detail.assid = " + mergsqls[2] + ".assid");
                sqls.append(" and " + mergsqls[1]);
            }
            sqls.append(" ) voucher where gl_cashflowcase.pk_detail = voucher.pk_detail ");
            sqls.append(" and gl_cashflowcase.pk_accountingbook in (" + pk_glorgbookssql.toString() + ") ");
            if (pk_innercorp != null && !pk_innercorp.trim().equals("")) {
                sqls.append(" and gl_cashflowcase.pk_innercorp = '" + pk_innercorp + "' ");
            }
            if (pk_currtype != null && !pk_currtype.equals("\u672c\u5e01") && !pk_currtype.equals("\u539f\u5e01")) {
                sqls.append(" and (gl_cashflowcase.pk_currtype = ");
                sqls.append(" '" + pk_currtype + "' or voucher.pk_currtype='" + pk_currtype + "') ");
            }
            sqls.append(" ) cashflow on cashflow.pk_cashflow = bd_cashflow.pk_cashflow ");
            if (includeSub) {
                IGeneralAccessor accessor = GeneralAccessorFactory.getAccessor((String)"08d4138b-a7b5-42fd-94bc-bb6eb7ac0fdc");
                List datas = accessor.getChildDocs(AccountBookUtil.getPk_org((String)pk_glorgbooks[0]), pk_cashflow, true);
                String[] pk_includeSub = new String[datas.size()];
                for (int i = 0; i < pk_includeSub.length; ++i) {
                    if (datas.get(i) == null) continue;
                    pk_includeSub[i] = NCESAPI.sqlEncode((String)((IBDData)datas.get(i)).getPk());
                }
                sqls.append(" where " + SqlUtils.getInStr((String)"bd_cashflow.pk_cashflow", (String[])pk_includeSub, (boolean)true));
            } else {
                sqls.append(" where bd_cashflow.pk_cashflow = '" + NCESAPI.sqlEncode((String)pk_cashflow) + "'");
            }
            con = this.getConnection();
            stmt = con.prepareStatement(sqls.toString());
            try (ResultSet rs = stmt.executeQuery();){
                while (rs.next()) {
                    Object t1 = rs.getObject(1);
                    if (t1 == null) continue;
                    res = new UFDouble(t1.toString());
                }
            }
        }
        catch (Exception e) {
            Logger.error((Object)e.getMessage(), (Throwable)e);
            throw new Exception(e.getMessage(), e);
        }
        finally {
            try {
                if (stmt != null) {
                    stmt.close();
                }
            }
            catch (Exception exception) {}
            try {
                if (con != null) {
                    con.close();
                }
            }
            catch (Exception exception) {}
        }
        this.afterCallMethod("nc.bs.gl.cashflowcaseio.CashFlowCaseIODMO", "getXJLL", new Object[]{pk_cashflow});
        return res;
    }

    public UFDouble getXJLLOfCJurrtypeByPeriod(CashFlowForIUFOCondVO qryVO) throws Exception {
        String pk_corps = qryVO.getOrgCode();
        String[] pk_glorgbooks = qryVO.getGlorgbooks();
        String subjCode = qryVO.getSubjCode();
        AssVO[] assItems = qryVO.getAssItems();
        String year1 = qryVO.getStartYear();
        String year2 = qryVO.getEndYear();
        String period1 = qryVO.getStartPeriod();
        String period2 = qryVO.getEndPeriod();
        String pk_cashflow = qryVO.getPk_cashflow();
        boolean flag = qryVO.getContainUnTally();
        String pk_currtype = qryVO.getPk_currtype();
        String rtnCurrtype = qryVO.getRtCuryType();
        String isDiff = qryVO.getIsDiff();
        String subjVersion = qryVO.getSubjVersion();
        if (pk_glorgbooks == null || pk_cashflow == null || year1 == null || year2 == null) {
            return UFDouble.ZERO_DBL;
        }
        StringBuilder pk_glorgbookssql = null;
        if (pk_glorgbooks != null && pk_glorgbooks.length > 0) {
            pk_glorgbookssql = new StringBuilder("");
            for (int i = 0; i < pk_glorgbooks.length; ++i) {
                pk_glorgbookssql.append("'").append(pk_glorgbooks[i]).append("'");
                if (i >= pk_glorgbooks.length - 1) continue;
                pk_glorgbookssql.append(",");
            }
        }
        if (pk_glorgbookssql == null) {
            return null;
        }
        UFDouble res = new UFDouble(0);
        Connection con = null;
        PreparedStatement stmt = null;
        try {
            AccountVO[] accounts = null;
            if (subjCode != null) {
                accounts = AccountUtilGL.getEndChildrenByCode((String[])pk_glorgbooks, (String)subjVersion, (String)subjCode, (String)subjCode, (boolean)true, null);
            }
            String accwhere = "";
            if (accounts != null) {
                String[] pk_accasoas = new String[accounts.length];
                for (int i = 0; i < accounts.length; ++i) {
                    pk_accasoas[i] = accounts[i].getPk_accasoa();
                }
                accwhere = SqlUtils.getInStr((String)"gl_detail.pk_accasoa", (String[])pk_accasoas, (boolean)true);
            }
            StringBuffer sqls = new StringBuffer("");
            if (rtnCurrtype.equals("\u8d26\u7c3f\u672c\u5e01")) {
                sqls.append("select sum(cashflow.moneymain) ");
            } else if (rtnCurrtype.equals("\u96c6\u56e2\u672c\u5e01")) {
                sqls.append("select sum(cashflow.moneygroup) ");
            } else if (rtnCurrtype.equals("\u5168\u5c40\u672c\u5e01")) {
                sqls.append("select sum(cashflow.moneyglobal) ");
            } else if (rtnCurrtype.equals("\u539f\u5e01")) {
                sqls.append("select sum(cashflow.money) ");
            } else {
                sqls.append(" select sum(cashflow.moneymain) ");
            }
            String[] mergsqls = ((IFreevalueReportQry)NCLocator.getInstance().lookup(IFreevalueReportQry.class)).formSqlByAssvos(assItems, null, Module.GL);
            sqls.append(" from bd_cashflow left outer join  ");
            sqls.append(" (select pk_cashflow,money,moneymain,moneygroup,moneyglobal from gl_cashflowcase , ");
            sqls.append(" (select pk_detail,pk_currtype from gl_detail");
            if (mergsqls != null) {
                sqls.append("," + mergsqls[0]);
            }
            sqls.append(" where gl_detail.discardflagv = 'N' ");
            sqls.append(" and gl_detail.dr = 0 ");
            sqls.append(" and isnull(gl_detail.errmessage,'~')='~'");
            sqls.append(" and isnull(gl_detail.errmessage2,'~')='~' ");
            sqls.append(" and gl_detail.voucherkindv not in  (2,4,5,255) ");
            if (isDiff != null && !isDiff.equals("2")) {
                sqls.append(" and gl_detail.isdifflag = " + (isDiff.equals("0") ? "'N' " : "'Y' "));
            }
            if (pk_glorgbooks != null) {
                sqls.append(" and gl_detail.pk_accountingbook in (" + pk_glorgbookssql.toString() + ") ");
            }
            if (year1 != null && year1.equals(year2) && period1 != null && period1.equals(period2)) {
                sqls.append(" and gl_detail.yearv = '" + year1 + "' and gl_detail.periodv = '" + period1 + "'");
            } else if (!year1.equals(year2)) {
                sqls.append(" and gl_detail.yearv||gl_detail.periodv >= '" + year1 + period1 + "' ");
                sqls.append(" and gl_detail.yearv||gl_detail.periodv <= '" + year2 + period2 + "' ");
            } else {
                if (year1 != null) {
                    sqls.append(" and gl_detail.yearv = '" + year1 + "' ");
                }
                if (period1 != null) {
                    sqls.append(" and gl_detail.periodv >='" + period1 + "' ");
                }
                if (period2 != null) {
                    sqls.append(" and gl_detail.periodv <='" + period2 + "' ");
                }
            }
            if (!flag) {
                sqls.append(" and gl_detail.pk_managerv <> 'N/A' ");
            }
            if (qryVO.getPk_unit() != null && !qryVO.getPk_unit().trim().equals("")) {
                sqls.append(" and gl_detail.pk_unit = '" + qryVO.getPk_unit() + "' ");
            }
            if (qryVO.getPk_profitcenter() != null && !qryVO.getPk_profitcenter().trim().equals("")) {
                sqls.append(" and gl_detail.pk_liabilitycenter = '" + qryVO.getPk_profitcenter() + "' ");
            }
            if (accounts != null && accounts.length > 0) {
                sqls.append(" and ").append(accwhere);
            }
            if (mergsqls != null) {
                sqls.append(" and gl_detail.assid = " + mergsqls[2] + ".assid");
                sqls.append(" and " + mergsqls[1]);
            }
            sqls.append(" ) voucher where gl_cashflowcase.pk_detail = voucher.pk_detail ");
            sqls.append(" and gl_cashflowcase.pk_accountingbook in (" + pk_glorgbookssql.toString() + " ) ");
            if (qryVO.getPk_innercorp() != null && !qryVO.getPk_innercorp().trim().equals("")) {
                sqls.append(" and gl_cashflowcase.pk_innercorp = '" + NCESAPI.sqlEncode((String)qryVO.getPk_innercorp()) + "' ");
            }
            if (pk_currtype != null && !pk_currtype.equals("\u672c\u5e01") && !pk_currtype.equals("\u539f\u5e01")) {
                sqls.append(" and (gl_cashflowcase.pk_currtype = ");
                sqls.append(" '" + NCESAPI.sqlEncode((String)pk_currtype) + "' or voucher.pk_currtype='" + NCESAPI.sqlEncode((String)pk_currtype) + "') ");
            }
            sqls.append(" ) cashflow on cashflow.pk_cashflow = bd_cashflow.pk_cashflow ");
            if (qryVO.isIncludeSub()) {
                IGeneralAccessor accessor = GeneralAccessorFactory.getAccessor((String)"08d4138b-a7b5-42fd-94bc-bb6eb7ac0fdc");
                List datas = accessor.getChildDocs(AccountBookUtil.getPk_org((String)pk_glorgbooks[0]), pk_cashflow, true);
                String[] pk_includeSub = new String[datas.size()];
                for (int i = 0; i < pk_includeSub.length; ++i) {
                    if (datas.get(i) == null) continue;
                    pk_includeSub[i] = ((IBDData)datas.get(i)).getPk();
                }
                sqls.append(" where " + SqlUtils.getInStr((String)"bd_cashflow.pk_cashflow", (String[])pk_includeSub, (boolean)true));
            } else {
                sqls.append(" where bd_cashflow.pk_cashflow = '" + NCESAPI.sqlEncode((String)pk_cashflow) + "'");
            }
            con = this.getConnection();
            stmt = con.prepareStatement(sqls.toString());
            try (ResultSet rs = stmt.executeQuery();){
                while (rs.next()) {
                    Object t1 = rs.getObject(1);
                    if (t1 == null) continue;
                    res = new UFDouble(t1.toString());
                }
            }
        }
        catch (Exception e) {
            Logger.error((Object)e.getMessage(), (Throwable)e);
            throw new SQLException(e.getMessage());
        }
        finally {
            try {
                if (stmt != null) {
                    stmt.close();
                }
            }
            catch (Exception exception) {}
            try {
                if (con != null) {
                    con.close();
                }
            }
            catch (Exception exception) {}
        }
        this.afterCallMethod("nc.bs.gl.cashflowcaseio.CashFlowCaseIODMO", "getXJLL", new Object[]{pk_cashflow});
        return res;
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    public UFDouble getXJLLOfFracCurrtype(String pk_corp, String pk_glorgbook, UFDate date1, UFDate date2, String pk_cashflow, boolean flag) throws SQLException {
        this.beforeCallMethod("nc.bs.gl.cashflowcaseio.CashFlowCaseIODMO", "getXJLL", new Object[]{pk_cashflow});
        if (pk_cashflow == null) {
            return null;
        }
        String sqls = "select sum(cashflow.moneyass) ";
        UFDouble res = new UFDouble(0);
        Connection con = null;
        PreparedStatement stmt = null;
        try {
            con = this.getConnection();
            stmt = con.prepareStatement(sqls);
            try (ResultSet rs = stmt.executeQuery();){
                while (rs.next()) {
                    Object t1 = rs.getObject(1);
                    if (t1 == null) continue;
                    res = new UFDouble(t1.toString());
                }
            }
        }
        finally {
            try {
                if (stmt != null) {
                    stmt.close();
                }
            }
            catch (Exception exception) {}
            try {
                if (con != null) {
                    con.close();
                }
            }
            catch (Exception exception) {}
        }
        this.afterCallMethod("nc.bs.gl.cashflowcaseio.CashFlowCaseIODMO", "getXJLL", new Object[]{pk_cashflow});
        return res;
    }

    public OperationResultVO reverseCashFlow(VoucherVO oldVoucher, VoucherVO newVoucher) throws BusinessException {
        int i;
        DetailVO[] oldVos = oldVoucher.getDetails();
        DetailVO[] newVos = newVoucher.getDetails();
        OperationResultVO rs = new OperationResultVO();
        if (oldVos == null || oldVos.length < 1 || newVos == null || newVos.length < 1) {
            return rs;
        }
        String[] oldPK = new String[oldVos.length];
        String[] newPK = new String[newVos.length];
        for (i = 0; i < oldPK.length; ++i) {
            oldPK[i] = oldVos[i].getPk_detail();
        }
        for (i = 0; i < newPK.length; ++i) {
            newPK[i] = newVos[i].getPk_detail();
        }
        if (oldPK.length != newPK.length) {
            return null;
        }
        try {
            CashFlowCaseOpDMO dmo = new CashFlowCaseOpDMO();
            CashflowcaseDMO cashdmo = new CashflowcaseDMO();
            for (int i2 = 0; i2 < oldPK.length; ++i2) {
                CashflowcaseVO[] cashflows = dmo.getCashFlowCase(oldPK[i2], 0);
                if (cashflows == null) continue;
                for (int j = 0; j < cashflows.length; ++j) {
                    cashflows[j].setMoney(cashflows[j].getMoney().multiply(-1.0));
                    cashflows[j].setPk_detail(newPK[i2]);
                }
                cashdmo.insertArray(cashflows, false);
            }
        }
        catch (Exception e) {
            this.reportException(e);
            rs.m_intSuccess = 2;
            rs.m_strDescription = NCLangResOnserver.getInstance().getStrByID("200235", "UPP200235-000019");
        }
        return rs;
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    public void deleteCaseByDetailPKs(String[] pk_details) throws SQLException {
        StringBuffer sqlAppend = new StringBuffer();
        for (int i = 0; i < pk_details.length; ++i) {
            sqlAppend.append("'");
            sqlAppend.append(NCESAPI.sqlEncode((String)pk_details[i]));
            sqlAppend.append("',");
        }
        String sql = "delete from gl_cashflowcase where pk_detail in (" + sqlAppend.toString().substring(0, sqlAppend.length() - 1) + ")";
        Connection con = null;
        Statement stmt = null;
        try {
            con = this.getConnection();
            stmt = con.createStatement();
            stmt.executeUpdate(sql);
        }
        finally {
            try {
                if (stmt != null) {
                    stmt.close();
                }
            }
            catch (Exception exception) {}
            try {
                if (con != null) {
                    con.close();
                }
            }
            catch (Exception exception) {}
        }
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    public void deleteCaseForCommonDetails(CommondetailVO[] commondetails) throws SQLException {
        if (commondetails == null || commondetails.length == 0) {
            return;
        }
        StringBuffer sqlAppend = new StringBuffer();
        for (CommondetailVO detail : commondetails) {
            if (detail.getPk_commondetail() == null) continue;
            sqlAppend.append("'");
            sqlAppend.append(NCESAPI.sqlEncode((String)detail.getPk_commondetail()));
            sqlAppend.append("',");
        }
        String sql = "delete from gl_cashflowcase where pk_sob in (" + sqlAppend.toString().substring(0, sqlAppend.length() - 1) + ")";
        Connection con = null;
        Statement stmt = null;
        try {
            con = this.getConnection();
            stmt = con.createStatement();
            stmt.executeUpdate(sql);
        }
        finally {
            try {
                if (stmt != null) {
                    stmt.close();
                }
            }
            catch (Exception exception) {}
            try {
                if (con != null) {
                    con.close();
                }
            }
            catch (Exception exception) {}
        }
    }

    private String[] getMoneyCurrencyMapForVoucher(DetailVO[] vos, HashMap<String, UFDouble> map, int type, QueryConditionVO qvo, HashMap accMap) {
        boolean flag = false;
        String[] pks = new String[vos.length];
        Object accTemp = null;
        for (int i = 0; i < vos.length; ++i) {
            UFDouble currentMoney;
            flag = false;
            pks[i] = vos[i].getPk_detail();
            accTemp = accMap.get(vos[i].getPk_accasoa());
            if (accTemp != null && ((AccountVO)accTemp).getCashtype() > 0) {
                flag = true;
            }
            if (!flag || !flag) continue;
            if (type == 0) {
                currentMoney = map.get(vos[i].getPk_currtype());
                if (vos[i].getLocaldebitamount().doubleValue() != 0.0) {
                    if (currentMoney == null) {
                        map.put(vos[i].getPk_currtype(), vos[i].getLocaldebitamount());
                    } else {
                        currentMoney = currentMoney.add(vos[i].getLocaldebitamount());
                        map.put(vos[i].getPk_currtype(), currentMoney);
                    }
                } else if (currentMoney == null) {
                    map.put(vos[i].getPk_currtype(), vos[i].getLocalcreditamount().multiply(-1.0));
                } else {
                    currentMoney = currentMoney.add(vos[i].getLocalcreditamount().multiply(-1.0));
                    map.put(vos[i].getPk_currtype(), currentMoney);
                }
            }
            if (type != 1) continue;
            currentMoney = map.get(vos[i].getPk_currtype());
            if (vos[i].getDebitamount().doubleValue() != 0.0) {
                if (currentMoney == null) {
                    map.put(vos[i].getPk_currtype(), vos[i].getDebitamount());
                    continue;
                }
                currentMoney = currentMoney.add(vos[i].getDebitamount());
                map.put(vos[i].getPk_currtype(), currentMoney);
                continue;
            }
            if (currentMoney == null) {
                map.put(vos[i].getPk_currtype(), vos[i].getCreditamount().multiply(-1.0));
                continue;
            }
            currentMoney = currentMoney.add(vos[i].getCreditamount().multiply(-1.0));
            map.put(vos[i].getPk_currtype(), currentMoney);
        }
        return pks;
    }

    private UFDouble getNativeAmount(DetailVO[] vos, HashMap accMap) {
        if (vos == null || vos.length == 0) {
            return UFDouble.ZERO_DBL;
        }
        UFDouble result = new UFDouble(0);
        for (int i = 0; i < vos.length; ++i) {
            Object accTemp = accMap.get(vos[i].getPk_accasoa());
            if (accTemp == null || ((AccountVO)accTemp).getCashtype() <= 0) continue;
            if (vos[i].getLocalcreditamount() != null) {
                result = result.sub(vos[i].getLocalcreditamount());
            }
            if (vos[i].getLocaldebitamount() == null) continue;
            result = result.add(vos[i].getLocaldebitamount());
        }
        return result;
    }

    /*
     * Enabled force condition propagation
     * Lifted jumps to return sites
     */
    private boolean checkCfForVoucher(DetailVO[] vos, HashMap<Object, Object> accMap, String strPKGLOrgbook, int type) throws Exception {
        if (!GLParaAccessor.isLiabilitycenterBalCheck((String)vos[0].getPk_org())) return this.checkCf(vos, accMap, strPKGLOrgbook, type);
        HashSet<String> liabilitycenterSet = new HashSet<String>();
        for (DetailVO detail : vos) {
            if (StringUtil.isEmptyWithTrim((String)detail.getPk_liabilitycenter())) continue;
            liabilitycenterSet.add(detail.getPk_liabilitycenter());
        }
        if (liabilitycenterSet.size() <= 1) return this.checkCf(vos, accMap, strPKGLOrgbook, type);
        HashMap detailMap = new HashMap();
        ArrayList<String> liabilitycenterList = new ArrayList<String>();
        for (DetailVO detail : vos) {
            if (StringUtil.isEmptyWithTrim((String)detail.getPk_liabilitycenter())) continue;
            if (detailMap.get(detail.getPk_liabilitycenter()) == null) {
                detailMap.put(detail.getPk_liabilitycenter(), new ArrayList());
                liabilitycenterList.add(detail.getPk_liabilitycenter());
            }
            ((List)detailMap.get(detail.getPk_liabilitycenter())).add(detail);
        }
        boolean check = true;
        for (String key : liabilitycenterList) {
            check = this.checkCf((DetailVO[]) ((List)detailMap.get(key)).toArray(new DetailVO[0]), accMap, strPKGLOrgbook, type);
            if (!check) continue;
            return true;
        }
        return false;
    }

    private boolean checkCf(DetailVO[] vos, HashMap<Object, Object> accMap, String strPKGLOrgbook, int type) throws Exception {
        CashFlowCaseOpDMO opDMO = new CashFlowCaseOpDMO();
        HashMap<String, UFDouble> map = new HashMap<String, UFDouble>();
        QueryConditionVO qvo = new QueryConditionVO();
        qvo.setPk_glorgbook(strPKGLOrgbook);
        String[] pk_details = this.getMoneyCurrencyMapForVoucher(vos, map, type, qvo, accMap);
        qvo.setPk_voucherDetail(pk_details);
        if (type == 0) {
            UFDouble cashflow = this.getNativeAmount(vos, accMap);
            return cashflow.compareTo((Object)opDMO.getCashFlowSumForCertainCurrency(qvo, null, type)) != 0;
        }
        HashSet<String> currencyTypeSet = new HashSet<String>();
        for (DetailVO onevo : vos) {
            AccountVO subjvo = (AccountVO)accMap.get(onevo.getPk_accasoa());
            if (subjvo.getCashtype() <= 0) continue;
            currencyTypeSet.add(onevo.getPk_currtype());
        }
        for (String pk_currtype : currencyTypeSet) {
            UFDouble analyzedCfAmount = opDMO.getCashFlowSumForCertainCurrency(qvo, pk_currtype, type);
            UFDouble voucherCfAmount = map.get(pk_currtype);
            if (analyzedCfAmount != null && analyzedCfAmount.compareTo((Object)voucherCfAmount) == 0 || this.isNullEqual(analyzedCfAmount, voucherCfAmount)) continue;
            return true;
        }
        return false;
    }

    private int isErrorInWhole(DetailVO[] vos, HashMap<Object, Object> accMap, String strPKGLOrgbook) throws Exception {
        String pa = null;
        try {
            pa = GLPubProxy.getRemoteGlPara().isCheckNativeAmount(vos[0].getPk_accountingbook());
        }
        catch (Exception e) {
            this.reportException(e);
            throw new BusinessException(NCLangResOnserver.getInstance().getStrByID("200235", "UPP200235-000012"));
        }
        if (this.checkCfForVoucher(vos, accMap, strPKGLOrgbook, 0)) {
            return 1;
        }
        if (pa != null && !pa.equalsIgnoreCase("N")) {
            if (this.checkCfForVoucher(vos, accMap, strPKGLOrgbook, 1)) {
                return 2;
            }
            return 0;
        }
        return 0;
    }

    public OperationResultVO[] checkSubAssSetting(VoucherSaveInterfaceVO vo, HashMap map) {
        int wrongDetail = -1;
        OperationResultVO rs = new OperationResultVO();
        OperationResultVO[] vs = new OperationResultVO[]{rs};
        VoucherVO voucher = vo.voucher;
        if (voucher == null || voucher.getDetails() == null) {
            return vs;
        }
        if (voucher.getVoucherkind() == 2) {
            return vs;
        }
        DetailVO[] vos = voucher.getDetails();
        try {
            HashSet<String> pkset = new HashSet<String>();
            for (int i = 0; i < vos.length; ++i) {
                if (vos[i].getPk_accasoa() == null) continue;
                pkset.add(vos[i].getPk_accasoa());
            }
            Set result = CFPubProxy.getRemoteCashFlowCase().isSubNeedAssCheck(vos[0].getPk_accountingbook(), pkset.toArray(new String[0]));
            for (int i = 0; i < vos.length; ++i) {
                Boolean isNeedCheck;
                AccountVO subjvo;
                boolean isBreak = false;
                String pk_accsubj = vos[i].getPk_accasoa();
                if (pk_accsubj == null || map.get(pk_accsubj) == null || (subjvo = (AccountVO)map.get(pk_accsubj)).getCashtype() > 0 || !(isNeedCheck = Boolean.valueOf(result.contains(pk_accsubj))).booleanValue()) continue;
                CashflowcaseVO[] cashflows = vos[i].getCashFlow();
                if (cashflows == null || cashflows.length == 0) {
                    wrongDetail = vos[i].getDetailindex();
                    isBreak = true;
                } else {
                    for (CashflowcaseVO onevo : cashflows) {
                        wrongDetail = vos[i].getDetailindex();
                        CashflowVO queryvo = new CashflowVO();
                        queryvo.setPk_cashflow(onevo.getPk_cashflow());
                        CashflowVO cfvo = new CashFlowCaseIOBO().getCashflow(queryvo, new Boolean(false));
                        if (cfvo.getItemflag() == null || !cfvo.getItemflag().equals("N")) continue;
                        wrongDetail = -1;
                        isBreak = true;
                        break;
                    }
                }
                if (isBreak) break;
            }
            if (wrongDetail != -1) {
                rs.m_intSuccess = 1;
                rs.m_strDescription = NCLangRes4VoTransl.getNCLangRes().getStrByID("2002gl55", "UPP2002gl55-000303", null, new String[]{"" + wrongDetail});
            }
        }
        catch (Exception e) {
            Logger.error((Object)e);
            Logger.error((Object)e.getMessage(), (Throwable)e);
        }
        return vs;
    }

    private boolean isNullEqual(UFDouble one, UFDouble two) {
        return !(one != null && one.doubleValue() != 0.0 || two != null && two.doubleValue() != 0.0);
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    public String getPKGLBook(String bookCode) throws SQLException {
        if (bookCode == null) {
            return null;
        }
        String sqls = "select pk_glbook from bd_glbook where code = '" + NCESAPI.sqlEncode((String)bookCode) + "'";
        String res = null;
        Connection con = null;
        PreparedStatement stmt = null;
        try {
            con = this.getConnection();
            stmt = con.prepareStatement(sqls);
            try (ResultSet rs = stmt.executeQuery();){
                while (rs.next()) {
                    Object t1 = rs.getObject(1);
                    if (t1 == null) continue;
                    res = t1.toString();
                }
            }
        }
        finally {
            try {
                if (stmt != null) {
                    stmt.close();
                }
            }
            catch (Exception exception) {}
            try {
                if (con != null) {
                    con.close();
                }
            }
            catch (Exception exception) {}
        }
        return res;
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    public String getPKGLOrg(String orgCode) throws SQLException {
        if (orgCode == null) {
            return null;
        }
        String sqls = "select pk_glorg from bd_glorg where glorgcode = '" + NCESAPI.sqlEncode((String)orgCode) + "'";
        String res = null;
        Connection con = null;
        PreparedStatement stmt = null;
        try {
            con = this.getConnection();
            stmt = con.prepareStatement(sqls);
            try (ResultSet rs = stmt.executeQuery();){
                while (rs.next()) {
                    Object t1 = rs.getObject(1);
                    if (t1 == null) continue;
                    res = t1.toString();
                }
            }
        }
        finally {
            try {
                if (stmt != null) {
                    stmt.close();
                }
            }
            catch (Exception exception) {}
            try {
                if (con != null) {
                    con.close();
                }
            }
            catch (Exception exception) {}
        }
        return res;
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    public String[] getPKGLOrgs(String[] orgCode) throws SQLException {
        if (orgCode == null) {
            return null;
        }
        StringBuffer orgcodes = new StringBuffer("");
        for (int i = 0; i < orgCode.length; ++i) {
            orgcodes.append("'" + NCESAPI.sqlEncode((String)orgCode[i]) + "',");
        }
        orgcodes = orgcodes.deleteCharAt(orgcodes.length() - 1);
        String sqls = "select pk_glorg from bd_glorg where glorgcode in (" + orgcodes.toString() + ")";
        String[] res = null;
        Connection con = null;
        PreparedStatement stmt = null;
        Vector<String> rsVec = new Vector<String>();
        try {
            con = this.getConnection();
            stmt = con.prepareStatement(sqls);
            try (ResultSet rs = stmt.executeQuery();){
                while (rs.next()) {
                    Object t1 = rs.getObject(1);
                    if (t1 == null) continue;
                    rsVec.add(t1.toString());
                }
            }
            res = new String[rsVec.size()];
            rsVec.copyInto(res);
        }
        finally {
            try {
                if (stmt != null) {
                    stmt.close();
                }
            }
            catch (Exception exception) {}
            try {
                if (con != null) {
                    con.close();
                }
            }
            catch (Exception exception) {}
        }
        return res;
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    public void deleteCaseOnKeyEvent(String pk_glorgbook) throws SQLException {
        String sql1 = "delete from gl_cashflowcase where gl_cashflowcase.pk_detail in( select gl_detail.pk_detail from gl_detail where exists (select 1 from bd_accsubj where gl_detail.pk_accsubj = bd_accsubj.pk_accsubj and bd_accsubj.cashbankflag = 0 and gl_detail.dr = 0)) and gl_cashflowcase.pk_glorgbook = '" + NCESAPI.sqlEncode((String)pk_glorgbook) + "'";
        String sql2 = "delete from gl_cashflowcase where gl_cashflowcase.pk_detail not in(select pk_detail from gl_detail where gl_detail.dr = 0)  and gl_cashflowcase.pk_glorgbook = '" + NCESAPI.sqlEncode((String)pk_glorgbook) + "'";
        Connection con = null;
        Statement stmt = null;
        try {
            con = this.getConnection();
            stmt = con.createStatement();
            stmt.executeUpdate(sql1);
            stmt.executeUpdate(sql2);
        }
        finally {
            try {
                if (stmt != null) {
                    stmt.close();
                }
            }
            catch (Exception exception) {}
            try {
                if (con != null) {
                    con.close();
                }
            }
            catch (Exception exception) {}
        }
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    public boolean isSameGLBook(String[] strPKGLOrgbooks) throws Exception {
        StringBuffer sqlAppend = new StringBuffer();
        for (int i = 0; i < strPKGLOrgbooks.length; ++i) {
            sqlAppend.append("'");
            sqlAppend.append(NCESAPI.sqlEncode((String)strPKGLOrgbooks[i]));
            sqlAppend.append("',");
        }
        String sqls = "select count(distinct(pk_glbook)) from bd_glorgbook";
        sqls = sqls + " where pk_glorgbook in (" + sqlAppend.toString().substring(0, sqlAppend.length() - 1) + ")";
        int result = 0;
        Vector vecResult = new Vector();
        Connection con = null;
        PreparedStatement stmt = null;
        try {
            con = this.getConnection();
            stmt = con.prepareStatement(sqls);
            try (ResultSet rs = stmt.executeQuery();){
                while (rs.next()) {
                    result = rs.getInt(1);
                }
            }
        }
        finally {
            try {
                if (stmt != null) {
                    stmt.close();
                }
            }
            catch (Exception exception) {}
            try {
                if (con != null) {
                    con.close();
                }
            }
            catch (Exception exception) {}
        }
        return result <= 1;
    }

    public VoucherVO copyForConvert(VoucherVO srcVoucher, VoucherVO destVoucher) throws BusinessException {
        if (destVoucher == null || destVoucher.getDetails() == null || destVoucher.getDetails().length == 0) {
            return destVoucher;
        }
        DetailVO[] details = destVoucher.getDetails();
        String[] pk_details = new String[destVoucher.getDetails().length];
        for (int i = 0; i < destVoucher.getDetails().length; ++i) {
            pk_details[i] = destVoucher.getDetails()[i].getPk_detail();
        }
        try {
            int i;
            CashflowcaseDMO cashflowcasedmo = new CashflowcaseDMO();
            CashflowcaseVO[] oldCaseVos = cashflowcasedmo.queryByPKDetails(pk_details);
            boolean isSame = false;
            if (nc.vo.gateway60.itfs.Currency.getMainCurrencyPK((String)srcVoucher.getPk_accountingbook()).equals(nc.vo.gateway60.itfs.Currency.getMainCurrencyPK((String)destVoucher.getPk_accountingbook()))) {
                isSame = true;
            }
            if (oldCaseVos == null || oldCaseVos.length == 0) {
                return destVoucher;
            }
            CashflowVO[] cashflowVOs = new CashflowDMO().queryCashflowVOsByPk_accountingbook(destVoucher.getPk_accountingbook());
            if (cashflowVOs == null || cashflowVOs.length == 0) {
                return destVoucher;
            }
            HashSet<String> pk_cashflowSet = new HashSet<String>();
            for (CashflowVO cashflowVO : cashflowVOs) {
                if (cashflowVO == null || cashflowVO.getPk_cashflow() == null) continue;
                pk_cashflowSet.add(cashflowVO.getPk_cashflow());
            }
            HashMap oldCaseMap = new HashMap();
            for (i = 0; i < oldCaseVos.length; ++i) {
                if (!pk_cashflowSet.contains(oldCaseVos[i].getPk_cashflow())) continue;
                if (oldCaseMap.get(oldCaseVos[i].getPk_detail()) != null) {
                    ((Vector)oldCaseMap.get(oldCaseVos[i].getPk_detail())).addElement(oldCaseVos[i]);
                    continue;
                }
                Vector<CashflowcaseVO> v = new Vector<CashflowcaseVO>();
                v.addElement(oldCaseVos[i]);
                oldCaseMap.put(oldCaseVos[i].getPk_detail(), v);
            }
            for (i = 0; i < details.length; ++i) {
                if (oldCaseMap.get(details[i].getPk_detail()) == null) continue;
                UserDataVO result = new UserDataVO();
                result.setDatatype(NCLangResOnserver.getInstance().getStrByID("200235", "UPP200235-000013"));
                Vector v_temp = (Vector)oldCaseMap.get(details[i].getPk_detail());
                CashflowcaseVO[] vo = new CashflowcaseVO[v_temp.size()];
                v_temp.copyInto(vo);
                for (int m = 0; m < vo.length; ++m) {
                    if (!isSame) {
                        vo[m].setMoneyass(new UFDouble(0));
                        UFDouble rate2 = nc.vo.gateway60.itfs.Currency.getRate((String)details[i].getPk_accountingbook(), (String)details[i].getPk_currtype(), (String)nc.vo.gateway60.itfs.Currency.getLocalCurrPK((String)details[i].getPk_accountingbook()), (UFDate)details[i].getPrepareddate());
                        CurrinfoVO currinfo = nc.vo.gateway60.itfs.Currency.getCurrRateInfo((String)details[i].getPk_accountingbook(), (String)details[i].getPk_currtype(), (String)nc.vo.gateway60.itfs.Currency.getLocalCurrPK((String)details[i].getPk_accountingbook()));
                        if (currinfo != null) {
                            boolean localCurrConvmode = currinfo == null ? true : currinfo.getConvmode().intValue() == ICurrinfoConst.CONVMODE_MULT.intValue();
                            int[] digitAndRoundtype = Currency.getCurrDigitAndRoundtype((String)details[i].getPk_currtype());
                            if (localCurrConvmode) {
                                vo[m].setMoneymain(vo[m].getMoney().multiply(rate2).setScale(Math.abs(digitAndRoundtype[0]), digitAndRoundtype[1]));
                            } else {
                                vo[m].setMoneymain(vo[m].getMoney().div(rate2).setScale(Math.abs(digitAndRoundtype[0]), digitAndRoundtype[1]));
                            }
                        }
                    }
                    vo[m].setPk_unit(destVoucher.getPk_org());
                }
                result.setUserdata((Object)vo);
                Vector<UserDataVO> v_oldUserData = details[i].getOtheruserdata();
                if (v_oldUserData != null && v_oldUserData.size() > 0) {
                    boolean blnHasCashFlowInfo = false;
                    for (int j = 0; j < v_oldUserData.size(); ++j) {
                        String pksubj;
                        AccountVO subvo;
                        UserDataVO udvo = (UserDataVO)v_oldUserData.elementAt(j);
                        if (udvo == null || !udvo.getDatatype().endsWith("\u73b0\u91d1\u6d41\u91cf") || (subvo = AccountUtilGL.findByPrimaryKey((String)(pksubj = details[i].getPk_accasoa()))).getCashtype() == null || subvo.getCashtype() == 0) continue;
                        v_oldUserData.setElementAt(result, j);
                        blnHasCashFlowInfo = true;
                        break;
                    }
                    if (!blnHasCashFlowInfo) {
                        v_oldUserData.addElement(result);
                    }
                } else {
                    v_oldUserData = new Vector<UserDataVO>();
                    v_oldUserData.addElement(result);
                }
                details[i].setOtheruserdata(v_oldUserData);
            }
        }
        catch (Exception e) {
            Logger.error((Object)e.getMessage(), (Throwable)e);
            throw new BusinessException(e.getMessage());
        }
        return destVoucher;
    }

    public OperationResultVO[] afterDelete(VoucherOperateInterfaceVO vo) throws BusinessException {
        try {
            new CashflowcaseDMO().deleteCashflowByVoucherPks(vo.pk_vouchers);
        }
        catch (Exception e) {
            throw new BusinessException((Throwable)e);
        }
        return null;
    }

    public OperationResultVO[] beforeDelete(VoucherOperateInterfaceVO vo) throws BusinessException {
        try {
            new CashflowcaseDMO().deleteCashflowByVoucherPks(vo.pk_vouchers);
        }
        catch (Exception e) {
            throw new BusinessException((Throwable)e);
        }
        return null;
    }

    public UFOCashFlowVO[] getXJLLOfCJurrtypeExForbatch(CashFlowForIUFOCondVO qryVO, boolean queryByPeriod) throws BusinessException {
        String pk_corps = qryVO.getOrgCode();
        String[] pk_glorgbooks = qryVO.getGlorgbooks();
        String subjCode = qryVO.getSubjCode();
        AssVO[] assItems = qryVO.getAssItems();
        String pk_cashflow = qryVO.getPk_cashflow();
        boolean flag = qryVO.getContainUnTally();
        String pk_currtype = qryVO.getPk_currtype();
        String rtnCurrtype = qryVO.getRtCuryType();
        String isDiff = qryVO.getIsDiff();
        boolean includeSub = qryVO.isIncludeSub();
        String pk_innercorp = qryVO.getPk_innercorp();
        String year1 = qryVO.getStartYear();
        String year2 = qryVO.getEndYear();
        String period1 = qryVO.getStartPeriod();
        String period2 = qryVO.getEndPeriod();
        String pk_unit = qryVO.getPk_unit();
        ArrayList<UFOCashFlowVO> cashvoList = new ArrayList<UFOCashFlowVO>();
        this.beforeCallMethod("nc.bs.gl.cashflowcaseio.CashFlowCaseIODMO", "getXJLLOfCJurrtypeEx", new Object[]{pk_cashflow});
        String groupField = " group by bd_cashflow.code ";
        String assFieldStr = "";
        ArrayList<String> assField = new ArrayList<String>();
        if (assItems != null && assItems.length > 0) {
            IFreeMap ifreemap = (IFreeMap)NCLocator.getInstance().lookup(IFreeMap.class.getName());
            GlAccAssinfoVO[] accassinfos = ifreemap.getAllAccAssInfo(Module.GL);
            HashMap<String, GlAccAssinfoVO> accassMap = new HashMap<String, GlAccAssinfoVO>();
            for (int i = 0; accassinfos != null && i < accassinfos.length; ++i) {
                accassMap.put(accassinfos[i].getPk_checktype(), accassinfos[i]);
            }
            for (AssVO vo : assItems) {
                GlAccAssinfoVO info = (GlAccAssinfoVO)accassMap.get(vo.getPk_Checktype());
                assFieldStr = assFieldStr + "," + info.getFieldName();
                assField.add(info.getFieldName());
            }
            groupField = groupField + assFieldStr;
        }
        String[] cashcode = pk_cashflow.split(",");
        Connection con = null;
        PreparedStatement stmt = null;
        try {
            AccountVO[] accounts = null;
            if (subjCode != null) {
                accounts = AccountByPkThreadCache.getInstance().getEndChildAccountVOs(pk_glorgbooks, subjCode, qryVO.getSubjVersion());
            }
            String accwhere = "";
            if (accounts != null) {
                String[] pk_accasoas = new String[accounts.length];
                for (int i = 0; i < accounts.length; ++i) {
                    pk_accasoas[i] = accounts[i].getPk_accasoa();
                }
                accwhere = SqlUtils.getInStr((String)"gl_detail.pk_accasoa", (String[])pk_accasoas, (boolean)true);
            }
            StringBuffer sqls = new StringBuffer("select ").append(groupField.replace("group by", ""));
            if (rtnCurrtype.equals("\u8d26\u7c3f\u672c\u5e01")) {
                sqls.append(",sum(cashflow.moneymain) money ");
            } else if (rtnCurrtype.equals("\u96c6\u56e2\u672c\u5e01")) {
                sqls.append(",sum(cashflow.moneygroup) money ");
            } else if (rtnCurrtype.equals("\u5168\u5c40\u672c\u5e01")) {
                sqls.append(",sum(cashflow.moneyglobal) money ");
            } else if (rtnCurrtype.equals("\u539f\u5e01")) {
                sqls.append(",sum(cashflow.money) money ");
            } else {
                sqls.append(",sum(cashflow.moneymain) money ");
            }
            String[] mergsqls = ((IFreevalueReportQry)NCLocator.getInstance().lookup(IFreevalueReportQry.class)).formSqlByAssvos(assItems, null, Module.GL);
            sqls.append(" from bd_cashflow inner join  ");
            sqls.append(" (select pk_cashflow,money,moneymain,moneygroup,moneyglobal");
            if (assField.size() > 0) {
                sqls.append(assFieldStr);
            }
            sqls.append(" from gl_cashflowcase , ");
            sqls.append(" (select pk_detail,pk_currtype ");
            if (assField.size() > 0) {
                sqls.append(assFieldStr);
            }
            sqls.append(" from gl_detail");
            if (mergsqls != null) {
                sqls.append("," + mergsqls[0]);
            }
            sqls.append(" where gl_detail.discardflagv = 'N' ");
            sqls.append(" and gl_detail.TEMPSAVEFLAG = 'N'");
            sqls.append(" and gl_detail.dr = 0 ");
            sqls.append(" and isnull(gl_detail.errmessage,'~')='~' ");
            sqls.append(" and isnull(gl_detail.errmessage2,'~')='~' ");
            sqls.append(" and gl_detail.voucherkindv not in  (2,4,5,255) ");
            if (isDiff != null && !isDiff.equals("2")) {
                sqls.append(" and gl_detail.isdifflag = " + (isDiff.equals("0") ? "'N' " : "'Y' "));
            }
            if (pk_glorgbooks != null) {
                sqls.append(" and gl_detail.pk_accountingbook = '" + pk_glorgbooks[0] + "' ");
            }
            if (queryByPeriod) {
                if (qryVO.getStartYear() != null && qryVO.getStartYear().equals(qryVO.getEndYear()) && qryVO.getStartPeriod() != null && qryVO.getStartPeriod().equals(qryVO.getEndPeriod())) {
                    sqls.append(" and gl_detail.yearv = '" + qryVO.getStartYear() + "' and gl_detail.periodv = '" + qryVO.getStartPeriod() + "'");
                } else if (year1 != null && year1.equals(year2) && period1 != null && period1.equals(period2)) {
                    sqls.append(" and gl_detail.yearv = '" + year1 + "' and gl_detail.periodv = '" + period1 + "'");
                } else if (!year1.equals(year2)) {
                    sqls.append(" and gl_detail.yearv||gl_detail.periodv >= '" + year1 + period1 + "' ");
                    sqls.append(" and gl_detail.yearv||gl_detail.periodv <= '" + year2 + period2 + "' ");
                } else {
                    if (year1 != null) {
                        sqls.append(" and gl_detail.yearv = '" + year1 + "' ");
                    }
                    if (period1 != null) {
                        sqls.append(" and gl_detail.periodv >='" + period1 + "' ");
                    }
                    if (period2 != null) {
                        sqls.append(" and gl_detail.periodv <='" + period2 + "' ");
                    }
                }
            } else {
                sqls.append(" and gl_detail.prepareddatev >= '" + qryVO.getStartdate().toString() + "' and gl_detail.prepareddatev <= '" + qryVO.getEnddate().toString() + "'");
            }
            if (!flag) {
                sqls.append(" and gl_detail.pk_managerv <> 'N/A' ");
            }
            if (pk_unit != null && !pk_unit.trim().equals("")) {
                sqls.append(" and gl_detail.pk_unit = '" + pk_unit + "' ");
            }
            if (qryVO.getPk_profitcenter() != null && !qryVO.getPk_profitcenter().trim().equals("")) {
                sqls.append(" and gl_detail.pk_liabilitycenter = '" + qryVO.getPk_profitcenter() + "' ");
            }
            if (accounts != null && accounts.length > 0) {
                sqls.append(" and ").append(accwhere);
            }
            if (mergsqls != null) {
                sqls.append(" and gl_detail.assid = " + mergsqls[2] + ".assid");
                sqls.append(" and " + mergsqls[1]);
            }
            sqls.append(" ) voucher where gl_cashflowcase.pk_detail = voucher.pk_detail ");
            sqls.append(" and gl_cashflowcase.pk_accountingbook = '" + NCESAPI.sqlEncode((String)pk_glorgbooks[0]) + "' ");
            if (pk_innercorp != null && !pk_innercorp.trim().equals("")) {
                sqls.append(" and gl_cashflowcase.pk_innercorp = '" + NCESAPI.sqlEncode((String)pk_innercorp) + "' ");
            }
            if (pk_currtype != null && !pk_currtype.equals("\u672c\u5e01") && !pk_currtype.equals("\u539f\u5e01")) {
                sqls.append(" and (gl_cashflowcase.pk_currtype = ");
                sqls.append(" '" + NCESAPI.sqlEncode((String)pk_currtype) + "' or voucher.pk_currtype='" + NCESAPI.sqlEncode((String)pk_currtype) + "') ");
            }
            sqls.append(" ) cashflow on cashflow.pk_cashflow = bd_cashflow.pk_cashflow ");
            IGeneralAccessor accessor = GeneralAccessorFactory.getAccessor((String)"08d4138b-a7b5-42fd-94bc-bb6eb7ac0fdc");
            IBDData[] datas = accessor.getDocByCodes(AccountBookUtil.getPk_org((String)pk_glorgbooks[0]), cashcode);
            HashSet<String> cashSet = new HashSet<String>();
            for (IBDData data : datas) {
                if (data == null) continue;
                cashSet.add(data.getPk());
            }
            if (includeSub) {
                String[] pk_cash = cashSet.toArray(new String[0]);
                cashSet.clear();
                for (String pk : pk_cash) {
                    List<IBDData> dataList = accessor.getChildDocs(AccountBookUtil.getPk_org((String)pk_glorgbooks[0]), pk, true);
                    for (IBDData dataSub : dataList) {
                        if (dataSub == null) continue;
                        cashSet.add(dataSub.getPk());
                    }
                }
            }
            sqls.append(" where " + SqlUtils.getInStr((String)"bd_cashflow.pk_cashflow", (String[])cashSet.toArray(new String[0]), (boolean)true));
            sqls.append(groupField);
            con = this.getConnection();
            stmt = con.prepareStatement(sqls.toString());
            try (ResultSet rs = stmt.executeQuery();){
                while (rs.next()) {
                    UFOCashFlowVO cashvo = new UFOCashFlowVO();
                    cashvo.setCashflowcode(rs.getString("code"));
                    if (assField.size() > 0) {
                        AssVO[] ass = new AssVO[assField.size()];
                        for (int i = 0; i < assField.size(); ++i) {
                            ass[i] = new AssVO();
                            ass[i].setPk_Checktype(assItems[i].getPk_Checktype());
                            ass[i].setPk_Checkvalue(rs.getString((String)assField.get(i)));
                        }
                        cashvo.setAssvos(ass);
                    }
                    cashvo.setAmout(new UFDouble(rs.getBigDecimal("money")));
                    cashvoList.add(cashvo);
                }
            }
        }
        catch (Exception e) {
            Logger.error((Object)e.getMessage(), (Throwable)e);
            throw new BusinessException(e.getMessage(), (Throwable)e);
        }
        finally {
            try {
                if (stmt != null) {
                    stmt.close();
                }
            }
            catch (Exception exception) {}
            try {
                if (con != null) {
                    con.close();
                }
            }
            catch (Exception exception) {}
        }
        this.afterCallMethod("nc.bs.gl.cashflowcaseio.CashFlowCaseIODMO", "getXJLL", new Object[]{pk_cashflow});
        if (assField.size() > 0) {
            this.transDoc(cashvoList);
        }
        return cashvoList.toArray(new UFOCashFlowVO[0]);
    }

    private void transDoc(List<UFOCashFlowVO> cashvoList) {
        HashMap<String, HashSet> docMap = new HashMap();
        for (UFOCashFlowVO vo : cashvoList) {
            for (AssVO ass : vo.getAssvos()) {
                if (FreeValueDefUtil.getInstance().isDefDoc(ass.getM_classid())) {
                    ass.setCheckvaluecode(ass.getPk_Checkvalue());
                    ass.setCheckvaluename(ass.getPk_Checkvalue());
                    continue;
                }
                if (docMap.get(ass.getM_classid()) == null) {
                    docMap.put(ass.getM_classid(), new HashSet());
                }
                ((HashSet)docMap.get(ass.getM_classid())).add(ass.getPk_Checkvalue());
            }
        }
        HashMap mapIndex = new HashMap();
        HashMap<String, AssVO> bdData = new HashMap<String, AssVO>();
        AssCodeConstructor constructor = new AssCodeConstructor();
        IBDData[] datas = null;
        for (String classid : docMap.keySet()) {
            datas = constructor.getBasedocs(null, classid, (String[]) ((HashSet)docMap.get(classid)).toArray(new String[0]));
            if (datas == null) continue;
            for (IBDData assVO : datas) {
                if (assVO == null) continue;
                bdData.put(assVO.getPk(), (AssVO) assVO);
            }
            mapIndex.put(classid, bdData);
        }
        for (UFOCashFlowVO vo : cashvoList) {
            for (AssVO assVO : vo.getAssvos()) {
                IBDData data = (IBDData)((HashMap)mapIndex.get(assVO.getM_classid())).get(assVO.getPk_Checkvalue());
                if (data == null) continue;
                if ("cd1f9a1c-eb08-493f-88ff-bcd1c134dee1".equals(AccAssItemCache.getClassIdByAccassItemPK((String)assVO.getPk_Checktype()))) {
                    assVO.setCheckvaluecode(((BankaccsubBDDataVO)data).getSubcode());
                    assVO.setCheckvaluename(((BankaccsubBDDataVO)data).getSubname().toString());
                    continue;
                }
                assVO.setCheckvaluecode(data.getCode());
                assVO.setCheckvaluename(data.getName().getText());
            }
        }
    }

    private CashflowVO[] queryCashFlowByPk_accountingbook(String pk_accountingbook) {
        String key = "cashflowvo#" + pk_accountingbook + "#" + Boolean.TRUE.toString();
        CashflowVO[] data = (CashflowVO[])GeneralThreadCache.getInstance().get(key);
        if (data == null) {
            CashflowVO qryVO = new CashflowVO();
            qryVO.setPk_glorgbook(pk_accountingbook);
            CashFlowVOLoader dataLoader = new CashFlowVOLoader(qryVO);
            GeneralThreadCache.getInstance().loadData(key, (IGeneralDataLoader)dataLoader);
            data = (CashflowVO[])GeneralThreadCache.getInstance().get(key);
        }
        return data;
    }
}
